import { AppRegistry } from 'react-native';

import Main from './main';
import List from './app/home/list';
import Detail from './app/home/detail';
import SubjectSub from './app/subject/sub';
import SubjectList from './app/subject/list';
import SubjectDetail from './app/subject/detail';
import Play from './app/play';
import Login from './app/home/login';

import React, { Component } from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    Button,
    View
} from 'react-native';
import {
    StackNavigator
} from 'react-navigation';
import Icon from 'react-native-vector-icons/Ionicons';

const StackOptions = ({navigation}) => {
    //console.log(navigation);
    let {state,goBack} = navigation;

    // 用来判断是否隐藏或显示header
    const visible= state.params.isVisible;
    let header;
    if (visible === true){
        header = null;
    }
    const headerStyle = {backgroundColor:'#6B6E80'};
    const headerTitle = state.params.title;
    const headerTitleStyle = {fontSize:20,color:'white',fontWeight:'500'};
    const headerBackTitle = false;
    const headerLeft = (
        <Button
            title=" < "
            color="white"
            isCustom={true}
            customView={
                            <Icon
                                name='ios-arrow-back'
                                size={30}
                                color='white'
                                style={{marginLeft:13}}
                            />
                       }
            onPress={()=>{goBack()}}
            />
    );
    return {headerStyle,headerTitle,headerTitleStyle,headerBackTitle,headerLeft,header}
};

const App = StackNavigator({
    Main: {
        screen: Main
    },
    List: {
        screen: List,
        navigationOptions: ({navigation}) => StackOptions({navigation})
    },
    Detail: {
        screen: Detail,
        navigationOptions: ({navigation}) => StackOptions({navigation})
    },
    SubjectSub: {
        screen: SubjectSub,
        navigationOptions: ({navigation}) => StackOptions({navigation})
    },
    SubjectList: {
        screen: SubjectList,
        navigationOptions: ({navigation}) => StackOptions({navigation})
    },
    SubjectDetail: {
        screen: SubjectDetail,
        navigationOptions: ({navigation}) => StackOptions({navigation})
    },
    Play: {
        screen: Play,
    },
    Login: {
        screen: Login
    }
}, {
    navigationOptions:{
        header: null,
        //headerStyle: { height: 20 }
    }
});

AppRegistry.registerComponent('kungfu', () => App);
